﻿@page "/"
@attribute [Authorize]

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

<Divider Text="EditorForm" />

<ValidateForm Model="starship" OnValidSubmit="@ValidSubmit">
    <EditorForm TModel="Starship">
        <FieldItems>
            <EditorItem @bind-Field="@starship.Identifier" Editable="false" />
        </FieldItems>
        <Buttons>
            <Button Text="提交" ButtonType="ButtonType.Submit" OnClick="@OnClick" />
        </Buttons>
    </EditorForm>
</ValidateForm>

@code {
    private Starship starship = new Starship() { ProductionDate = DateTime.UtcNow };

    private void HandleValidSubmit()
    {

    }

    private void OnClick()
    {

    }

    private Task ValidSubmit(EditContext context)
    {
        return Task.CompletedTask;
    }

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);
    }

    public class Starship
    {
        [Display(Name = "主键")]
        [Required(ErrorMessage = "这里是必填项")]
        [StringLength(16, ErrorMessage = "Identifier too long (16 character limit).")]
        public string Identifier { get; set; }

        [Display(Name = "描述")]
        public string Description { get; set; }

        [Required]
        public string Classification { get; set; }

        [Range(1, 100000, ErrorMessage = "Accommodation invalid (1-100000).")]
        public int MaximumAccommodation { get; set; }

        [Required]
        [Range(typeof(bool), "true", "true",
            ErrorMessage = "This form disallows unapproved ships.")]
        public bool IsValidatedDesign { get; set; }

        [Required]
        public DateTime ProductionDate { get; set; }
    }
}